<?php
namespace AiChongWu\Controller;
use Think\Controller;
/**
 * Created by PhpStorm.
 * User: medivh
 * Date: 15-6-24
 * Time: 上午10:23
 */
Class WeChatSdkController extends Controller{
    public function sdk(){
        $options = array(
            'token'=>'aichongwu100', //填写你设定的key
        );
        $weObj = new Wechat($options);
//        $weObj->valid();//明文或兼容模式可以在接口验证通过后注释此句，但加密模式一定不能注释，否则会验证失败
        $type = $weObj->getRev()->getRevType();
        /**
         * 判断返回事件，做出相应回应
         */
        switch($type) {
            case Wechat::MSGTYPE_TEXT:
                $weObj->text("您的消息我们收到啦，请稍等哦")->reply();
                break;
            case Wechat::MSGTYPE_IMAGE:
                $weObj->text("你的照片好可爱哦")->reply();
                break;
            case Wechat::MSGTYPE_LOCATION:
                $weObj->text("你的位置我们收到啦")->reply();
                break;
            case Wechat::MSGTYPE_LINK:
                $weObj->text("这是个什么链接呢???")->reply();
                break;
            case Wechat::MSGTYPE_EVENT:
                $EventType = $weObj->getRev()->getRevEvent();
                switch($EventType['event']){
                    case Wechat::EVENT_MENU_CLICK:
                        $weObj->text("你点击的菜单\r\n回执是".$EventType['key']."\r\n但是喵喵还在开发中\r\n等喵喵成长之后\r\n再陪你玩儿好吗\r\n请一定要等我哦")->reply();
                        break;
                    case Wechat::EVENT_SUBSCRIBE:
//                        $weObj->text("感谢您的关注呢，喵喵在这里给您请安啦，么么哒\r\n不过呢，喵喵目前还没有长大\r\n据说程序员哥哥正在奋斗\r\n请等待那么点时间，程序员哥哥很快就能把我制造出来啦")->reply();
                        $news = array(
                            "0"=>array(
                                'Title'=>'喵喵感谢您的关注呢',
                                'Description'=>'给您请安啦，喵喵正在努力开发中，请耐心等待，喵喵长大以后能知道很多很多知识呢，可以帮助您更好的关心爱护我们，不要离开好吗',
                                'PicUrl'=>'http://public.weirongm.com/AiChongWu/images/07.jpg',
                                'Url'=>''
                            )
                        );
                        $weObj->news($news)->reply();
                        break;
                    case Wechat::EVENT_LOCATION:
                        $msg = $weObj->getRevData();
//                        $weObj->text("哇哦～好厉害，喵喵收到您的地址了呢\r\nlatitude:".$msg['Latitude']."\r\nLongitude".$msg['Longitude'])->reply();
                        break;
                    case Wechat::EVENT_SCAN:
                        $weObj->text("能来到这里也不容易，我就收下你的膝盖了")->reply();
                        break;
                    default:
                        $weObj->text("喵喵有点不能理解了\r\n这是key：".$EventType['key']."\r\n这是event：".$EventType['event']."\r\n偷偷的告诉你\r\n你可以把这个结果反馈给我哦")->reply();
                }
                break;
            case Wechat::MSGTYPE_MUSIC:
                $weObj->text("哇，好好听???")->reply();
                break;
            case Wechat::EVENT_SUBSCRIBE:
                $weObj->text("谢谢您的关注哦")->reply();
                break;
            case Wechat::EVENT_SCAN:
                $weObj->text("您打开了宝藏哦")->reply();
                break;
            case Wechat::EVENT_MENU_CLICK:
                $weObj->text("asd")->reply();
                break;
            default:
                $weObj->text("喵喵有点不能理解了，您能重新说一遍吗")->reply();
        }

    }

    /**
     * 微信菜单
     */
    public function menu(){
        $options = array(
            'appid' => 'wx6c5fcc716e19267e',//填写高级调用功能的app id
 			'appsecret' => '02c466a6eaaef8f34e566b53084ffd87' //填写高级调用功能的密钥
        );
        $MenuData = array (
           'button' => array (
               0 => array (
                   'name' => '爱宠日常',
                   'sub_button' => array (
                       0 => array (
                           'type' => 'view',
                           'name' => '喵星人日常',
                           'url' => 'http://weixin.weirongm.com/AiChongWu/News/GetCode/column/18 ',
                           ),
                       1 => array (
                           'type' => 'view',
                           'name' => '汪星人日常',
                           'url' => 'http://weixin.weirongm.com/AiChongWu/News/GetCode/column/19 ',
                           ),
                       ),
                   ),
               1 => array (
                   'name' => '拍爱宠',
                   'sub_button' => array (
                       0 => array (
                           'type' => 'click',
                           'name' => '喵喵请您耐心哦',
                           'key' => 'center_0',
                           ),
                       ),
                   ),
               2 => array (
                   'name' => '新手秘籍',
                   'sub_button' => array (
                       0 => array (
                           'type' => 'view',
                           'name' => '养喵必备',
                           'url' => 'http://weixin.weirongm.com/AiChongWu/News/GetCode/column/20 ',
                           ),
                       1 => array (
                           'type' => 'view',
                           'name' => '养汪必备',
                           'url' => 'http://weixin.weirongm.com/AiChongWu/News/GetCode/column/21 ',
                           ),
//                       2 => array (
//                           'type' => 'click',
//                           'name' => '幸运之轮',
//                           'key' => 'right_2',
//                           ),
//                       3 => array (
//                           'type' => 'click',
//                           'name' => '宠物小百科',
//                           'key' => 'right_3',
//                           ),
//                       4 => array (
//                           'type' => 'click',
//                           'name' => '每日一签',
//                           'key' => 'right_4',
//                           )

                    ),
                ),
     	    ),
      	);
        $wechat = new Wechat($options);
        $istrue = $wechat -> createMenu($MenuData);
        echo $istrue;
        dump($wechat->getMenu());
    }
    public function aa(){
        echo "hello world by jay liu";
    }
}